package com.paipai.config;


import com.paipai.interceptor.JwtRenewInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebMvcConfig implements WebMvcConfigurer {

    @Autowired
    JwtRenewInterceptor jwtRenewInterceptor;


    public void addViewControllers(ViewControllerRegistry registry) {
        //WebMvcConfigurer.super.addViewControllers(registry);

        //注册 路径和视图的匹配关系
        registry.addViewController("/proj/register").setViewName("register");
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        List<String> exclude = new ArrayList<>();

        exclude.add("/**/*login*/**");
        exclude.add("/**/*Login*/**");
        exclude.add("/**/*Email*/**");
        exclude.add("/**/*email*/**");


        exclude.add("/**/*register*/**");
        exclude.add("/**/*Register*/**");

        exclude.add("/**/*success*/**");

        exclude.add("/**/*error*/**");

        exclude.add("/**/*dataPanel*/**");

        exclude.add("/**/*confirm*/**");

        exclude.add("/**/*business*/**");

        exclude.add("/**/*.png");

        exclude.add("/**/*.js");

        exclude.add("/**/*.css");

        exclude.add("/**/*.jpg");
        exclude.add("/**/*.html");

        registry.addInterceptor(jwtRenewInterceptor).addPathPatterns("/**").excludePathPatterns(exclude);
    }
}
